//
//  MainTabBar.swift
//  0623微博(swift)
//
//  Created by 岳挺 on 15/6/24.
//  Copyright © 2015年 yueting. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        print(__FUNCTION__)
        
        print(composeBtn)
        let count :CGFloat = 5
        
        let w = frame.size.width / count
        let rect = CGRectMake(0, 0, w, frame.size.height)
        
        var i :CGFloat = 0
        
        for btn in subviews
        {
            if btn is UIControl && !(btn is UIButton)
            {
                btn.frame = CGRectOffset(rect, i * w, 0)
                i += i == 1 ? 2 : 1
            }
        }
        
        composeBtn.frame = CGRectOffset(rect, 2 * w, 0)
    }
    
    //composeBtn的懒加载
    lazy var composeBtn : UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:UIControlState.Normal )
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        self.addSubview(btn)
        return btn
        }()
    
    

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
